package routes

import (
	"shyxy-model-agent/core/application"
	"shyxy-model-agent/core/services"
	"shyxy-model-agent/core/types"
	"shyxy-model-agent/pkg/model"

	"github.com/gofiber/fiber/v2"
)

func RegisterTestRoutes(app *fiber.App, application *application.Application) {
	app.Get("/test/create/onlineModel", func(ctx *fiber.Ctx) error {
		dbLoader := application.DBLoader()
		name := "qwen-max"
		typ := types.ModelTypeOnline
		description := "A test online model"
		category := "test"
		grpcExecutableFileName := "rpc_server_qwen"
		grpcArguments := ""
		uri := "https://dashscope.aliyuncs.com/api/v1"
		apiKey := "sk-971e63b147b14e5fa91d83d7c8f2540d"
		return services.InsertOnlineModelInfo(name, typ, description, category, grpcExecutableFileName, grpcArguments, uri, apiKey, dbLoader.ModelInfoRepo(), dbLoader.OnlineModelRepo())
	})
	app.Get("/test/preload/:modelName", func(ctx *fiber.Ctx) error {
		modelLoader := application.ModelLoader()
		modelName := ctx.Params("modelName")

		opts := []model.Option{
			model.WithModelID(modelName),
			model.WithModel(modelName),
			model.WithAssetDir("."),
		}
		_, err := modelLoader.Load(application.DBLoader(), opts...)
		if err != nil {
			fiber.NewError(fiber.StatusInternalServerError, err.Error())
		}
		return ctx.SendString("ok")
	})
	app.Get("/test/list/:modelName", func(ctx *fiber.Ctx) error {
		modelLoader := application.ModelLoader()
		modelName := ctx.Params("modelName")
		model, err := modelLoader.ListModelByID(modelName)
		if err != nil {
			return fiber.NewError(fiber.StatusInternalServerError, err.Error())
		}
		return ctx.JSON(model.ID)
	})
}
